package com.yonyou.pmclouds.team.mapper;

import com.yonyou.pmclouds.basecom.dao.BaseMapper;
import com.yonyou.pmclouds.team.entity.TeamMemberVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TeamMapper extends BaseMapper<TeamMemberVO> {

    String[] queryExistMember(@Param("projectid") String projectid, @Param("members") String[] members);

    /**
     * 查询项目团队的所有人，这里认为一般项目团队规模不会太大
     */
    TeamMemberVO[] queryTeamByProject(String projectid);

    TeamMemberVO[] queryByIds(String[] ids);
    
    TeamMemberVO[] queryByPkUsers(String[] pkUsers);

    String[] queryProjectByUser(@Param("user") String user, @Param("pkTenant") String pkTenant,
                                @Param("state") Byte state, @Param("start") int start, @Param("offset") int offset);
    //补充，根据user以及项目状态数组查询
    String[] queryProjectByUserAndStatus(@Param("user") String user, @Param("pkTenant") String pkTenant,
                                @Param("statuses") Byte[] state, @Param("start") int start, @Param("offset") int offset);

    int countProjectByUser(@Param("user") String user, @Param("pkTenant") String pkTenant,
                           @Param("state") Byte state);
    /**
     * 计数当前项目当前公司的成员的数量，排除项目经理
     * */
    int countMemberByEntAndProj(@Param("enterprise") String enterprise, @Param("project")String project);

    Integer[] isPersonInProject(@Param("user") String user, @Param("pkTenant") String pkTenant, @Param("projectid") String projectid);

    TeamMemberVO[] queryTeamByProjectAndEnts(@Param("project") String project,
                                       @Param("entids") String[] entids);
    TeamMemberVO[] queryByPkUsers(String pkProject,String[] pkUsers);

    // 计数当前项目下的所有成员数量
    int countProjectMembers(@Param("projectid") String projectid);

    TeamMemberVO[] queryMembersByEntAndProjects(@Param("tenantId") String tenantId, @Param("entId") String entId, @Param("pkProjects") String[] pkProjects);

    String[] queryMembersByEnt(@Param("tenantId") String tenantId, @Param("entId") String entId);

    String[] queryProjectsByEnt(@Param("tenantId") String tenantId, @Param("entId") String entId);

    List<TeamMemberVO> queryByUserAndTenant(@Param("pkUser") String pkUser, @Param("tenantId") String tenantId);

    /**
     * 根据租户和项目查询企业
     *
     * @param tenantId
     * @param projectId
     * @return
     */
    List<TeamMemberVO> queryEnterpriseByProjectAndTenant(@Param("tenantId") String tenantId, @Param("projectId") String projectId);

    @Select("select * from pmbd_team_member where pk_project = #{pkProject} and pk_user in  (${pkUsers}) and dr = 0 ")
    TeamMemberVO[] getByProjectAndUsers(@Param("pkProject") String pkProject, @Param("pkUsers") String pkUsers);

    TeamMemberVO[] queryByprojects(String[] pkProjects);

    TeamMemberVO[] queryByEnterprise(@Param("pkTenant") String pkTenant, @Param("pkEnterprise") String pkEnterprise);

    /**
     * 查询同时参与多个项目的user
     * @param pkTenant
     * @param pkProjects
     * @param start
     * @param offset
     * @return
     */
    String[] queryInnerSecUserByPorjects(@Param("pkTenant") String pkTenant,
                                         @Param("pkProjects") String[] pkProjects,
                                         @Param("projectSize") int projectSize,
                                         @Param("start") int start,
                                         @Param("offset") int offset);

    /**
     * 查询同时参与多个项目user数量
     * @param pkTenant
     * @param pkProjects
     * @param start
     * @param offset
     * @return
     */
    Integer countInnerSecUserByPorjects(@Param("pkTenant") String pkTenant,
                                    @Param("pkProjects") String[] pkProjects,
                                    @Param("projectSize") int projectSize,
                                    @Param("start") int start,
                                    @Param("offset") int offset);

}
